<script src="../color_picker/mootools.v1.11.js" type="text/javascript"></script>
<script src="../color_picker/nogray_core_vs1_min.js" type="text/javascript"></script>
<script src="../color_picker/nogray_color_picker_vs2_min.js" type="text/javascript"></script>

<script language="javascript">
	window.addEvent('domready', function(){
		var color1 = new ColorPicker('Color1', 'Color1_div');
		var color2 = new ColorPicker('Color_a', 'Color_a_div', {onComplete: function(){
				alert(this.color);
			}
		});
	});
</script>
<style>
	* {font-family:Arial, Helvetica, sans-serif;
		font-size:9pt;}
	.sample_swatch {float:left;
		width:20px;
		height:20px;
		cursor:pointer;}
		
	/* table list */
	.table_list {border-collapse:collapse;
		border:solid #cccccc 1px;
		width:100%;}
	
	.table_list td {padding:5px;
		border:solid #efefef 1px;}
	
	.table_list th {background:#75b2d1;
		padding:5px;
		color:#ffffff;}
	
	.table_list tr.odd {background:#e1eff5;}
</style>
<?

$pathdb="../upload";
$path = "../upload";
if (isset($_POST['butSaveLoai'])) {
	$image = $_POST['txtImage'];
	$parent = $_POST['txtParent'];
	$sort = (int)$_POST['txtSortOrder'];
	$status=($_POST['chkShow']!=''?1:0);
	$notsub=($_POST['chknotsub']!=''?1:0);
	$mau=$_POST['mau'];
				
	$CategoryName = trim($_POST['txtName']);
	$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;.jpeg;",50000*1024,0);
	
	if ($CategoryName=="")
	{
		echo "<p align=center class='err'>B&#7841;n ch&#432;a nh&#7853;p tên danh m&#7909;c</p>";
	}
	else
	{
		if (!empty($_POST['oldid'])) {
			$oldid = $_POST['oldid'];
			$sql = "update newscategories set categories_name='".$CategoryName."', parent_id='".$parent."', sort_order='".$sort."',status='".$status."',language='".$mau."' where categories_id='".$oldid."'";
		}
		else 
			$sql = "insert into newscategories (categories_name,parent_id,sort_order, status,language) values ('".$CategoryName."','".$parent."','".$sort."','".$status."','".$mau."')";
	}
	if (mysql_query($sql,$con)) {
			if(empty($_POST['oldid'])) {
					$oldid = mysql_insert_id();
			}		
			$sqlUpdateField = "";
			
			if ($_POST['chkClear']=='')
			{
				// delete old image
			//	$news= GetNewsInfo($oldid);
			//	if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				
				//upload new image
				$ext=GetFileExtention($_FILES['txtImage']['name']);
				if (MakeUpload($_FILES['txtImage'],"$path/bg$oldid$ext"))
				{
					@chmod("$path/bg$oldid$ext", 0777);
					$sqlUpdateField = " categories_description='$pathdb/bg$oldid$ext' ";
				}			
			}
			else 
			{
				// delete old image
				//$news= GetNewsInfo($oldid);
				//if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				$sqlUpdateField = " categories_description='' ";
			}
			
			// update image
			if($sqlUpdateField)
			{
				$sqlUpdate = "update newscategories set $sqlUpdateField where categories_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
			
			//echo $sqlUpdateField." ".$oldid;exit(0);
		}	
		else {
	$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
		echo "<p align=center class='err'>&#272;ã c&#7853;p nh&#7853;t thành công</p><br>";
			echo "<script>window.location='index.php?act=new_danhmuc&cat=".$_REQUEST['cat']."&page=".$_REQUEST['page']."'</script>";
	
	
} 
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$sql = "select * from newscategories where categories_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);
			$CategoryName=$row['categories_name'];
			$notsub=$row['categories_notsub'];
			$parent=$row['parent_id'];
			$order=$row['sort_order'];
			$status=$row['categories_status'];
			$mau=$row['language'];
			
		
		
		}
	}
?>

<form method="POST" name="FormLoaiSP"  enctype="multipart/form-data"  action="index.php">
<input type=hidden name="act" value="new_danhmuc_m">
<input type=hidden name="oldid" value="<? echo $oldid; ?>">
<input type=hidden name="page" value="<? echo $_REQUEST['page']; ?>">
<input type=hidden name="cat" value="<? echo $_REQUEST['cat']; ?>">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" align="center" class="title" height="20">S&#7917;a &#273;&#7893;i / C&#7853;p nh&#7853;t : Danh m&#7909;c Tin T&#7913;c </td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="4" bordercolor="#111111" width="124%" id="AutoNumber2" cellspacing="0">
<? if (GetConfig('multilanguage')==1)
{
?>
	  
<?
}
?>
      <tr>
        <td width="15%" class="smallfont">
        <p align="right">Tên danh m&#7909;c</td>
        <td width="1%" class="smallfont">
        <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $CategoryName; ?>" TYPE="text" NAME="txtName" CLASS=textbox size="34"></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont">
        <p align="right">Hình &#7843;nh</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
        </td>
        <td width="83%" class="smallfont">
		<INPUT TYPE="file" NAME="txtImage" CLASS=textbox size="34"><input type="checkbox" name="chkClear" value="ON">
		Xóa 
		b&#7887; hình<span class="style1">(Cập nhật hình LOGO)</span></td>
      </tr>
      
            	  <tr>
        <td width="20%" class="smallfont">
        <p align="right">Chon mot ma mau</td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="78%" class="smallfont">
		      <center>
<!-- Begin: AdBrite -->
<script type="text/javascript">
   var AdBrite_Title_Color = '0000FF';
   var AdBrite_Text_Color = '000000';
   var AdBrite_Background_Color = 'FFFFFF';
   var AdBrite_Border_Color = 'FFFFFF';
</script>
</center>
<div id="Color1_div" class="sample_swatch" style="background:#000000;">&nbsp;</div>
<input type="text" size="6" id="Color1"  NAME="mau"   value="<?=$mau?>"/></td>
      </tr> 
    <tr>
        <td width="15%" class="smallfont">
        <p align="right">Thu&#7897;c danh m&#7909;c</td>
        <td width="1%" class="smallfont">&nbsp;        </td>
        <td width="83%" class="smallfont">
        <select size="1" name="txtParent">
<?
		echo "<option value='0'>[Danh m&#7909;c g&#7889;c]</option>";
		$cats=GetListNewCategory();
		foreach ($cats as $cat)
		{
			if ($cat[0]==$parent)
				echo "<option value=".$cat[0]." selected>".$cat[1]."</option>";
			else
				echo "<option value=".$cat[0].">".$cat[1]."</option>";
		}
?>		
		</select></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont" align="right">
        Không hi&#7875;n th&#7883;</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<input type="checkbox" name="chkShow" value="ON" <? if ($status>0) echo 'checked' ?>></td>
      </tr>
<!--      <tr>
        <td width="15%" class="smallfont" align="right">
        Không có danh m&#7909;c con</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<input name="chknotsub" type="checkbox" value="ON" checked="checked" <? if ($notsub>0) echo 'checked' ?>></td>
      </tr>    -->   
      <tr>
        <td width="15%" class="smallfont" align="right">
        Th&#7913; t&#7921; s&#7855;p x&#7871;p</td>
        <td width="1%" class="smallfont" align="right">&nbsp;        </td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $order; ?>" TYPE="text" NAME="txtSortOrder" CLASS=textbox size="34"></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont">
		<p align="right"><INPUT TYPE="submit" NAME="butSaveLoai" VALUE=" L&#432;u " CLASS=button>&nbsp;</td>
        <td width="1%" class="smallfont">&nbsp;		</td>
        <td width="83%" class="smallfont"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>
